package com.ciko.code.adapter;

import android.content.Context;
import android.view.View;

import com.ciko.code.base.adapter.CommonAdapter;
import com.ciko.code.base.adapter.ViewHolder;
import com.ciko.code.bean.RecodeListEntity;
import com.ciko.code.bean.WorkFlowEntity;
import com.ciko.code.type.EmployeeEnum;
import com.ciko.code.utils.DateUtil;
import com.mywork.R;

import java.util.List;


public class WorkFlowAdapter
		extends
		CommonAdapter<RecodeListEntity>
{

	private WorkFlowEntity		   workFlowEntity;
	private boolean				   isLast;
	private List<RecodeListEntity> mDatas;

	public WorkFlowAdapter(Context context, List<RecodeListEntity> mDatas, int itemLayoutId, WorkFlowEntity workFlowEntity, boolean isLast) {
		super(context, mDatas, itemLayoutId);
		this.workFlowEntity = workFlowEntity;
		this.isLast = isLast;
		this.mDatas = mDatas;
	}

	@Override
	public void convert(ViewHolder helper, RecodeListEntity item) {

		helper.setText(R.id.tvNum, helper.getPosition() + 1);
		if (helper.getPosition() == 0)
		{
			helper.getView(R.id.ll_ReciveTime).setVisibility(View.VISIBLE);
			helper.getView(R.id.ll_DealTime).setVisibility(View.GONE);
			helper.getView(R.id.ll_Advice).setVisibility(View.GONE);
			helper.setText(R.id.tvReciveTimeName, "申请时间：");
			helper.setText(R.id.tvReciveTime, DateUtil.longToDate(item.getFlowTime(), 4));
			helper.getView(R.id.iv_status).setVisibility(View.INVISIBLE);
			helper.getView(R.id.ll2).setVisibility(View.VISIBLE);
		}
		else
		{
			helper.getView(R.id.ll_ReciveTime).setVisibility(View.GONE);
			helper.getView(R.id.ll_DealTime).setVisibility(View.VISIBLE);
			helper.getView(R.id.ll_Advice).setVisibility(View.VISIBLE);
			helper.getView(R.id.ll2).setVisibility(View.GONE);
			helper.setText(R.id.tvDealTime, DateUtil.longToDate(item.getFlowTime(), 4));
			if (item.getFlowReviewOpinions() == null)
			{
				helper.setText(R.id.tvAdvice, item.getFlowRecode());
			}
			else
			{
				helper.setText(R.id.tvAdvice, item.getFlowReviewOpinions());
			}
			helper.getView(R.id.iv_status).setVisibility((item.getFlowRecode() == null || item.getFlowRecode().equals("")) ? View.INVISIBLE : View.VISIBLE);
			helper.getView(R.id.iv_status).setBackgroundResource(item.getFlowRecode().equals("同意") ? R.drawable.res_agree_bg : R.drawable.res_refuse_bg);
			if (helper.getPosition() == mDatas.size()-1 && isLast)
			{
				helper.getView(R.id.iv_status).setBackgroundResource(R.drawable.renshi_finish);
				helper.getView(R.id.ll_Advice).setVisibility(View.GONE);
				helper.setText(R.id.tvDealTimeName, "归档时间：");
			}
		}
		helper.setText(R.id.tvJob, EmployeeEnum.typeOfValue(item.getUserRole()));
		helper.setText(R.id.tvName, item.getPerUserName());
		helper.setRoundImageUrl(R.id.ivHanderIcon, mDatas.get(helper.getPosition()).getUserHead(), R.drawable.test_header);
	}

}
